package sctu.edu.java.year2016.team06.chenqiang.day20160521.chapter4_3;

/**
 * 编写Java程序，使用while循环语句计算1+1/2!+1/3!…1/20!之和.
 */
public class Chapter4_3 {
    public static void main(String[] args) {
        System.out.println("该算式的和为：");
        double sum = 0, x = 1;
        int i = 1;
        while (i <= 20) {
            sum = sum + x;
            i++;
            x = x / (1.0 * i);
        }
        System.out.println(sum);
    }
}